package com.carskeeper.controller.body;

import com.alibaba.dubbo.config.annotation.Reference;
import com.carskeeper.body.service.BodyUserService;
import com.carskeeper.common.dtos.PageResponseResult;
import com.carskeeper.common.dtos.ResponseResult;
import com.carskeeper.model.body.dtos.InsertBodyUserDto;
import com.carskeeper.model.body.vo.BodyUserListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "主体用户")
@RestController
@RequestMapping("/body/user")
public class BodyUserController {

    @Reference
    private BodyUserService bodyUserService;

    /**
     * 添加管理员
     * @param dto
     * @return
     */
    @ApiOperation("添加管理员")
    @PostMapping("/addAmin")
    public ResponseResult addAdmin(@RequestBody InsertBodyUserDto dto){
        return bodyUserService.addAdmin(dto);
    }

    /**
     * 查询用户
     * @param id
     * @return
     */
    @ApiOperation("查询用户列表")
    @GetMapping("/findUserList")
    public PageResponseResult<List<BodyUserListVo>> findUserList(Long id,
                                                                 @RequestParam(defaultValue ="1") Integer pageNum,
                                                                 @RequestParam(defaultValue ="10") Integer pageSize)
    {
        return bodyUserService.findUserList(id,pageNum,pageSize);
    }

    /**
     * 密码重置
     * @param id
     * @return
     */
    @ApiOperation("密码重置")
    @GetMapping("/reset")
    public ResponseResult reset(Long id)
    {
        return bodyUserService.reset(id);
    }

    /**
     * 锁定
     * @param id
     * @return
     */
    @ApiOperation("锁定")
    @GetMapping("/lock")
    public ResponseResult lock(Long id)
    {
        return bodyUserService.lockUser(id,true);
    }

    /**
     * 解锁
     * @param id
     * @return
     */
    @ApiOperation("解锁")
    @GetMapping("/unlock")
    public ResponseResult lockUser(Long id)
    {
        return bodyUserService.lockUser(id,false);
    }
}
